class UserNotifier < ActionMailer::Base
  def signup_notification(user)
    setup_email(user)
    @subject    += ' Activa tu cuenta.'
    body( :user => user,
      :url  => url_for(:host => StringSetting.find_by_name("site-host").value, :controller => :account, :action => :activate, :id => user.activation_code))
  end
  
  # Esto es más que inútil...
#  def activation(user)
#    setup_email(user)
#    @subject    += 'Tu cuenta ha sido activada'
#    body :url  => url_for (:host => StringSetting.find_by_name("site-host").value, :controller => :account, :action => :index)
#  end

  def recover(user)
    setup_email(user)
    @subject = ' Nuevo password'
    body( :user => user,
      :url  => url_for(:host => StringSetting.find_by_name("site-host").value, :controller => :account, :action => :recover_password, :id => user.crypted_password))
  end
  
  protected
  def setup_email(user)
    #DONE: Si esto funciona, hacerlo configurable en la interfaz
    ActionMailer::Base.smtp_settings = { :address => "itesm.mx", :domain => "gmail.com", :authentication => :login, 
      :user_name => "a01130356", :password => "851426" }
  #  ActionMailer::Base.smtp_settings = { :address => StringSetting.find_by_name("smtp-server").value,
  #                                       :port => IntegerSetting.find_by_name("smtp-port").value,
  #                                       :domain => StringSetting.find_by_name("site-host").value,
  #                                       :authentication => StringSetting.find_by_name("smtp-auth-method").value,
  #                                       :user_name => StringSetting.find_by_name("smtp-auth-login").value,
  #                                       :password => StringSetting.find_by_name("smtp-auth-passwd").value }
    recipients  "#{user.email}"
    from        StringSetting.find_by_name("admin-mail").value
    @subject    = StringSetting.find_by_name("site-name").value + " Powered By Contenid-OS:"
    sent_on     Time.now
  end
end
